package com.syg.servlet11_Filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;

public class _03_FilterChain implements Filter{

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public _03_FilterChain() {
        logger.info("C1,filter无参构造执行了(第三个filter)");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("C2,filter初始化方法执行了(第三个filter)");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");
        logger.info("C3,filter放行之前(第三个filter)");
        filterChain.doFilter(servletRequest,servletResponse);
        logger.info("C4,filter放行之后(第三个filter)");
    }

    @Override
    public void destroy() {
        logger.info("C5,Filter销毁了(第三个filter)");
    }
}
